package com.rpframework.module.common.bottom.entity.po;

import com.rpframework.core.json.ParameterException;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * 地理对象
 * Created by jump on 2016/8/9.
 */
public class Geography implements Serializable {
    /**
     * 经度
     */
    private Double longitude;
    /**
     * 纬度
     */
    private Double latitude;
    /**
     * 绝对地址
     */
    private String address;


    public Geography(Double longitude, Double latitude) {
        this.longitude = longitude;
        this.latitude = latitude;
    }

    public Geography() {
    }

    public Geography(String address) {
        this.address = address;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Double getLongitude() {
        return longitude;
    }

    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }

    public Double getLatitude() {
        return latitude;
    }

    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }

    /**
     * 基本验证
     *
     * @param entity  对象
     * @param address 是否检查地址
     */
    public static void baseValidate(Geography entity, Boolean address) {
        if (entity == null) throw new ParameterException("Geography NULL");
        if (entity.getLatitude() == null || entity.getLongitude() == null) {
            String da = entity.getAddress();
            String am = "详细地址";
            if (address != null) {
                if (address) {
                    if (StringUtils.isBlank(da)) {
                        throw new ParameterException(am + "不能为空");
                    }
                }
            } else {
                if (!StringUtils.isBlank(da)) {
                    return;
                }
            }
            throw new ParameterException(am + "/经度/纬度不能为空");
        }
    }

    /**
     * 智能验证
     */
    public static void baseValidate(Geography entity) {
        baseValidate(entity, null);
    }
}
